Optimizing Graphics Performance
Manual     Reference     Scripting   
Unity Manual > Advanced > Optimizing Graphics Performance

Optimizing Graphics Performance

Desktop

Making your game run smoothly is critical to its success. Thankfully Unity is there for you! We have spent a lot of time and energy making Unity iOS run fast on a wide variety of hardware. Below are some simple guidelines to maximizing the speed of your game.

In Summary - Combine, Combine, Combine

  • If you care about performance, combine meshes.
  • If you care about performance, make sure all of your combined meshes also share the same material and texture.
  • The Profiler and Rendering Statistics window are very helpful!

In Detail:

Modern graphics cards are really good at pushing a lot of polygons, but they have quite a bit of overhead for every batch that you submit to the graphics card. So if you have a 100-triangle object it is going to be just as expensive to render as a 1500-triangle object. The "sweet spot" for optimal rendering performance is somewhere around 1500-4000 triangles per mesh.

You only pay a rendering cost for objects that have a Mesh Renderer attached. And you only pay for those that are within the view frustum. There is no rendering cost from having a lot of empty GameObjects in your scene.

  • The best way to improve rendering performance is to combine objects together so each mesh has around 1500 or more triangles and uses only one Material for the entire mesh.

It is important to understand that just combining two objects which don't share a material does not give you any performance increase at all. If you want to combine effectively, you need to make sure your mesh uses only one material after you have combined it.

There is, however, one thing to be aware of when combining objects: if you use a lot of small lights in your scene, it might make sense to combine only objects that are close to each other.

The rendering cost for a mesh that has multiple materials is the same as having multiple renderers for each material. The most common reason why you have multiple materials is that two meshes don't share the same textures. So, if you want to optimize rendering performance, you need to make sure that the objects you combine share textures.

  • Unity is very good at pushing lots of polygons. Unity uploads all geometry to the graphics card for good cache utilization and optimal data alignment.
  • You simply have to make sure that the graphics card doesn't have to handle large numbers of batches.
  • If you use Forward rendering path, the number of Pixel Lights affecting an object heavily affects performance.

Pixel Lights in Forward Rendering Path

Note: this applies only to Forward rendering path.

If you use pixel lighting, then each GameObject has to be rendered as many times as there are pixel lights that affect the object. If you combine two objects that are very far apart, it might increase the size of the object and now you have a lot of lights affecting this big object. If your objects were separate however, the light won't have to be applied on the part of the mesh which is far away. This can result in rendering the combined mesh as many times as the uncombined mesh (thus not saving anything). For this reason, you should keep GameObjects that are very far away as individual Meshes.

When rendering a mesh, Unity finds all lights surrounding the mesh. It then figures out what lights affect the mesh the most. The QualitySettings are used to modify how many of the lights end up as pixel lights and how many as vertex lights.

Every light calculates its importance based on how far away it is from the mesh and how intense it is.

Some lights are more important than others depending on the game context. For this reason, every light has a Render Mode setting which can be set to Important or Not Important.

Imagine the player's car with head lights driving through the night. The head lights are the most important light in the game. For this reason, the head lights Render Mode should be set to Important.

If you have a light that is not very important and also visually doesn't gain much from being a pixel light, set the lights Render Mode to Not Important. This way, you don't waste rendering performance or lose any visual quality.

Per-Layer Cull Distances

You might want to cull small objects earlier to reduce number of draw calls. For example, small rocks and debris could be made invisible at much smaller distance than large buildings. To do that, put small objects into a separate layer and setup per-layer cull distances using the Camera.layerCullDistances script function.

Shadows

If you are deploying for Desktop platforms then you should pay attention to shadows; shadows are generally expensive. They can add a lot of performance overhead to your game if they are not used correctly. For more details about shadows, please read the Shadows page.

Note: Remember that shadows are not currently supported on iOS or Android devices.

See Also

Android

Unity Android is currently in preparation for Unity 3. Therefore, this documentation is not yet complete. Please watch this space for proper Unity Android documentation as it is added.

Page last updated: 2011-02-28